package ar.edu.itba.tp1.tpalan;

import ar.edu.itba.tp1.gps.api.GPSRule;
import ar.edu.itba.tp1.gps.api.GPSState;
import ar.edu.itba.tp1.gps.exception.NotAppliableException;


/**
 * GPSRule interface.
 */
public class MyGPSRule implements GPSRule {

	private Colour colour;
	private Integer cost;
	
	public MyGPSRule(Colour colour, int cost) {
		this.colour = colour;
		this.cost = cost;
	}
	
	/**
	 * Provides the cost of the rule.
	 * @return The cost of the rule.
	 */
	public Integer getCost() {
		return this.cost;
	}
	
	public Colour getColour(){
		return colour;
	}
	
	/**
	 * Provides the name of the rule so it can be
	 * clearly identified by an human being.
	 * @return The name of the rule.
	 */
	public String getName() {
		return "Change to " + this.colour.toString();
	}
	
	@Override
	public String toString() {
		return getName();
	}
	
	/**
	 * Computes the next state based on the previous one.
	 * The next state is the result of applying the rule to
	 * the previous state.
	 * @param state The previous state of the problem.
	 * @return The next state of the problem.
	 * @throws NotAppliableException if the rule can not be
	 * applied to the received state.
	 */
	public GPSState evalRule(GPSState state) throws NotAppliableException {
		return ((MyGPSState)state).changeColour(this.colour);
	}
}
